<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="急救车牌号" prop="vin" label-width="90px">
        <el-input
          v-model="queryParams.vin"
          placeholder="请输入急救车牌号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="司机" prop="driverName" label-width="90px">
        <el-input
          v-model="queryParams.driverName"
          placeholder="请输入司机"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="医生" prop="doctorName" label-width="90px">
        <el-input
          v-model="queryParams.doctorName"
          placeholder="请输入医生"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="调度接收时间" prop="receiveHelpTime" size="small" label-width="150px;">
        <el-date-picker type="daterange" v-model="receiveHelpTime" format="yyyy-MM-dd" size="small" value-format="yyyy-MM-dd"
          start-placeholder="开始日期" end-placeholder="结束日期" @change="handleChangeReceiveTime" range-separator="至" clearable></el-date-picker>
      </el-form-item>

      <el-form-item label="出车时间" prop="leaveHospTime" size="small" label-width="150px;">
        <el-date-picker type="daterange" v-model="leaveHospTime" format="yyyy-MM-dd" size="small" value-format="yyyy-MM-dd"
          start-placeholder="开始日期" end-placeholder="结束日期" @change="handleChangeLeaveTime" range-separator="至" clearable></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8"> </el-row>

    <el-table
      v-loading="loading"
      :data="tradeList"
      @selection-change="handleSelectionChange"
      height="60vh"
    >
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <!-- <el-table-column label="对账ID" align="center" prop="billID" /> -->
      <el-table-column
        label="流水"
        align="center"
        prop="flow"
        :show-overflow-tooltip="true"
      >
      <template slot-scope="scope">
        <router-link :to="'/dispatch/dispatch?dispatchID=' + scope.row.dispatchID">
          <span>
            {{ scope.row.flow }}
          </span>
        </router-link>
      </template>

      </el-table-column>
      <!-- <el-table-column label="车费" align="center" prop="carFee" /> -->
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <span
            :style="scope.row.status == '1' ? 'color:red' : 'color:green'"
            >{{ statusFormat(scope.row) }}</span
          >
        </template>
      </el-table-column>
      <el-table-column
        label="调度信息接收时间"
        align="center"
        prop="receiveHelpTime"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.receiveHelpTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="出车时间"
        align="center"
        prop="leaveHospTime"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.leaveHospTime) == undefined
              ? "暂无"
              : parseTime(scope.row.leaveHospTime)
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车牌号" align="center" prop="vin" >

        <template slot-scope="scope">
          <router-link :to="'/ambu/car?carID=' + scope.row.carID">
          <span>
            {{ scope.row.vin }}
          </span>
          </router-link>
        </template>
      </el-table-column>

      <el-table-column
        label="收治医院"
        align="center"
        prop="hospital"
      />


      <el-table-column
        label="患者姓名"
        align="center"
        prop="patientName"
      />
      <!--      <el-table-column label="检车费" align="center" prop="checkCarFee" />
      <el-table-column label="药品费" align="center" prop="medicineFee" />
      <el-table-column label="结款方式" align="center" prop="payType" />
      <el-table-column label="结算状态" align="center" prop="payStatus" />
      <el-table-column label="缴费流水" align="center" prop="payTrade" /> -->
      <!-- <el-table-column label="状态" align="center" prop="status" /> -->
      <!-- <el-table-column label="医院标识" align="center" prop="uid" /> -->
<!--      <el-table-column-->
<!--        label="操作"-->
<!--        align="center"-->
<!--        class-name="small-padding fixed-width"-->
<!--      >-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            v-hasPermi="['manager:trade:edit']"-->
<!--            >查看</el-button-->
<!--          >-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改对账管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="调度标识" prop="dispatchID">
          <el-input v-model="form.dispatchID" placeholder="请输入调度标识" />
        </el-form-item>
        <el-form-item label="车费" prop="carFee">
          <el-input v-model="form.carFee" placeholder="请输入车费" />
        </el-form-item>
        <el-form-item label="检车费" prop="checkCarFee">
          <el-input v-model="form.checkCarFee" placeholder="请输入检车费" />
        </el-form-item>
        <el-form-item label="药品费" prop="medicineFee">
          <el-input v-model="form.medicineFee" placeholder="请输入药品费" />
        </el-form-item>
        <el-form-item label="缴费流水" prop="payTrade">
          <el-input v-model="form.payTrade" placeholder="请输入缴费流水" />
        </el-form-item>
        <el-form-item label="医院标识" prop="uid">
          <el-input v-model="form.uid" placeholder="请输入医院标识" />
        </el-form-item>
        <el-form-item label="流水" prop="flow">
          <el-input v-model="form.flow" placeholder="请输入流水" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listTrade,
  getTrade,
  delTrade,
  addTrade,
  updateTrade,
  exportTrade
} from "@/api/biz/trade";

export default {
  name: "Trade",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      receiveHelpTime:[],
      leaveHospTime:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 对账管理表格数据
      tradeList: [],
      // 结束标识字典
      isOverOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dispatchID: undefined,

        carFee: undefined,

        checkCarFee: undefined,

        medicineFee: undefined,

        payType: undefined,

        payStatus: undefined,

        payTrade: undefined,

        status: undefined,

        uid: undefined,

        flow: undefined,
        doctorName: undefined,
        driverName:undefined,
        receiveHelpTime:undefined,
        endReceiveHelpTime: undefined,
        leaveHospTime:undefined,
        endLeaveHospTime:undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        dispatchID: [
          { required: true, message: "调度标识不能为空", trigger: "blur" }
        ],

        uid: [{ required: true, message: "医院标识不能为空", trigger: "blur" }],

        flow: [{ required: true, message: "流水不能为空", trigger: "blur" }]
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("trade_status").then(response => {
      this.isOverOptions = response.data;
    });
  },
  methods: {
    todetail(row) {

    },
    statusFormat(row, column) {
      // 派车 出车 取消 返回
      return this.selectDictLabel(this.isOverOptions, row.status);
    },
    /** 查询对账管理列表 */
    getList() {
      this.loading = true;
      listTrade(this.queryParams).then(response => {
        this.tradeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        billID: undefined,

        dispatchID: undefined,

        carFee: undefined,

        checkCarFee: undefined,

        medicineFee: undefined,

        payType: undefined,

        payStatus: "0",

        payTrade: undefined,

        status: "0",

        uid: undefined,

        flow: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.receiveHelpTime = [];
      this.leaveHospTime = [];
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.billID);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加对账管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const billID = row.billID || this.ids;
      getTrade(billID).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改对账管理";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.billID != undefined) {
            updateTrade(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addTrade(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    // 时间查询方法
    handleChangeReceiveTime() {
      this.queryParams.receiveHelpTime = this.receiveHelpTime[0];
      this.queryParams.endReceiveHelpTime = this.receiveHelpTime[1];
    },
    // 时间查询方法
    handleChangeLeaveTime() {
      this.queryParams.leaveHospTime = this.leaveHospTime[0];
      this.queryParams.endLeaveHospTime = this.leaveHospTime[1];
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const billIDs = row.billID || this.ids;
      this.$confirm(
        '是否确认删除对账管理编号为"' + billIDs + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delTrade(billIDs);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有对账管理数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportTrade(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        })
        .catch(function() {});
    }
  }
};
</script>
<style scoped="scoped">
/* 分页 */
.pagination-container {
  height: 80px;
  margin-top: 0px;
  padding: 23px 20px !important;
}
/* 分页  end */
</style>
